#!/bin/sh
#
# 'stop' - Shell script a la RedHat initialization routines

if [ "$1" = "" ]
 then
  BASE=/applications/assp;
 else
  BASE=$1;
fi
export BASE
pidfile=$BASE/pid
pidfile2=$BASE/pid_Secondary


if [ `cat $pidfile`  ]
	then 
	echo "Stopping ASSP with PID `cat $pidfile` in $BASE"
	password=$BASE/password.txt
	echo `cat $password` | sudo -S kill -TERM `cat $pidfile`
fi

if [ `cat $pidfile2`  ]
	then 
	echo "Stopping Secondary with PID `cat $pidfile2` in $BASE"
	password=$BASE/password.txt
	echo `cat $password` | sudo -S kill -TERM `cat $pidfile2`
fi




sleep 10

echo "Restarting ASSP Anti-SPAM Proxy server in $BASE"

trap '' 1
LANG=
export LANG
echo `cat $password` | sudo -S perl $BASE/assp.pl $BASE


if [ `cat $pidfile`  ]
	then 
	echo -e "\n"
	echo "ASSP is running with PID `cat $pidfile`"
fi
